<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        console.log(Array.prototype);
        //给原型对象拓展内置对象方法
        Array.prototype.sum = function () {
            let sum = 0;
            for (let i = 0; i < this.length; i++) {
                // console.log(this)      this指向调运者
                // console.log(this[i])   1,2,5
                sum += this[i];      
            }
            return sum;
        };

        let arr=[1,2,5];
        console.log(arr.sum());
        console.log(Array.prototype);    //此时Array里面的原型对象里就有sum方法了

        const arr1=new Array(1,2,3);
        console.log(arr1.reverse());
        console.log(arr1.sum());
    </script>
</body>

</html>